package top.xia17.plugins.fast.common.security.auditor;

import org.springframework.data.domain.AuditorAware;
import top.xia17.plugins.fast.common.security.SecUtil;

import java.util.Optional;

/**
 * jpa保存时自动生成操作人
 * @author xia17
 * @date 2022/1/17
 */
public class JpaSecurityAuditorAware implements AuditorAware<String> {

    @Override
    public Optional<String> getCurrentAuditor() {
        String userName = SecUtil.getUsername();
        return Optional.of(userName == null ? "system" : userName);
    }

}
